
(function($) {
    var i = 1;
    var methods = {
        _download: function(options) {
            var triggerDelay = (options && options.delay) || 200;
            var removeDelay = (options && options.removeDelay) || 100000;
            if (options.source === "server") {
                this.each(function(index, item) {
                    methods._createIFrame(item, index * triggerDelay, removeDelay);

                    console.log("download times : "+ i)
                    i ++;
                });
            };
            if (options.source === "local") {
                this.each(function(index, item) {
                    methods._createLink(item, index * triggerDelay, removeDelay);
                });
            };
 
 
        },
        _createIFrame: function(url, triggerDelay, removeDelay) {

            setTimeout(function() {
                var frame = $('<iframe style="display: none;" class="multi-download"></iframe>');
                frame.attr('src', url);
                $(document.body).after(frame);
                setTimeout(function() {
                    frame.remove();
                }, removeDelay);
            }, triggerDelay);
        },
        //download
        _createLink: function(url, triggerDelay, removeDelay) {
            var aLink = document.createElement("a"),
                evt = document.createEvent("HTMLEvents");
 
            evt.initEvent("click");

            aLink.download = "";
            aLink.href = url;
            aLink.dispatchEvent(evt);

        }
    };
 
    $.fn.multiDownload = function(options) {
        methods._download.apply(this, arguments);
    };
 
})(jQuery);
